//
//  GoodsCell.m
//  收纳
//
//  Created by  on 2022/10/28.
//

#import "GoodsCell.h"
#import "SignCell.h"
@interface GoodsCell()
@property (strong, nonatomic) IBOutlet UIImageView *img;
@property (strong, nonatomic) IBOutlet UILabel *name;
@property (strong, nonatomic) IBOutlet UILabel *money;
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@property (strong, nonatomic) IBOutlet UILabel *date;

@end
@implementation GoodsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.collectionView registerNib:[SignCell nib] forCellWithReuseIdentifier:[SignCell ID]];
}
- (void)setModel:(Goods *)model{
    _model = model;
    self.img.image = [UIImage imageWithData:model.imgs[0]];
    self.name.text = model.name;
    self.money.text = model.money;
    self.date.text = [NSDate transToDate:@"yyyy-MM-dd HH:mm:ss" :model.stamp];
    [self.collectionView reloadData];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.model.signArray.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    SignCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:[SignCell ID] forIndexPath:indexPath];
    cell.title.text = self.model.signArray[indexPath.row];
    return  cell;
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
}

#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *str = self.model.signArray[indexPath.row];
    CGSize size = [str sizeWithFont:[UIFont systemFontOfSize:14]];
    return  CGSizeMake(ceil(size.width) + 30,38);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return  UIEdgeInsetsMake(10, 5, 16, 5);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

@end
